# Maintainer: fauxpark <fauxpark@gmail.com>

_realname=gdb
_target=avr

pkgbase=mingw-w64-${_target}-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_target}-${_realname}
pkgver=12.1
pkgrel=1
pkgdesc='The GNU Debugger for AVR (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('GPL')
url='https://www.gnu.org/software/gdb/'
groups=("${MINGW_PACKAGE_PREFIX}-${_target}-toolchain")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-gmp")
depends=("${MINGW_PACKAGE_PREFIX}-readline")
source=(https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.xz{,.sig}
        '0001-readline-8.2.patch'::https://sourceware.org/git/?p=binutils-gdb.git\;a=patch\;h=1add37b567a7dee39d99f37b37802034c3fce9c4)
sha256sums=('0e1793bf8f2b54d53f46dea84ccfd446f48f81b297b28c4f7fc017b818d69fed'
            'SKIP'
            '10239536c197e98f6057fd72ea40b4c73ced2402d54fe02ecb5772b7e793cb16')
validpgpkeys=('F40ADB902B24264AA42E50BF92EDB04BFF325CF3') # Joel Brobecker

prepare() {
    cd "${srcdir}"/${_realname}-${pkgver}
    patch -p1 -i "${srcdir}"/0001-readline-8.2.patch
}

build() {
    [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
    mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

    ../${_realname}-${pkgver}/configure \
        --build=${MINGW_CHOST} \
        --prefix=${MINGW_PREFIX} \
        --target=${_target} \
        --disable-nls \
        --disable-debug \
        --disable-dependency-tracking \
        --disable-binutils \
        --disable-libssp \
        --disable-install-libbfd \
        --disable-install-libiberty \
        --disable-werror \
        --with-system-readline

    make
}

package() {
    cd "${srcdir}/build-${MSYSTEM}"

    make DESTDIR="$pkgdir" install-gdb

    cd ${pkgdir}${MINGW_PREFIX}

    # Remove files that conflict with native gdb
    rm -rf include share/gdb share/info
}
